//
//  JddBaseViewController.m
//  PlayBall
//
//  Created by Edward Zhang on 12-5-4.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "JddBaseViewController.h"
#import "JddGlobal.h"
#import "UIFitButton.h"
@interface JddBaseViewController ()

@end

@implementation JddBaseViewController

@synthesize fromController;

-(void)setNavigationBarHidden:(BOOL )hidden{
    [self.navigationController setNavigationBarHidden:hidden];
}

-(void)setJddTabBarHidden:(BOOL)hidden{
    JddTabBar *tabBar = [JddGlobal sharedInstance].tabBar;
    hidden ? [tabBar hide] : [tabBar show];
}

-(void)setTabBarItemSelect:(NSInteger)item{
    JddTabBar *tabBar = [JddGlobal sharedInstance].tabBar;
    switch (item) {
        case 1:
            [tabBar setSelectedItem:tabBar.item1];
            break;
        case 2:
            [tabBar setSelectedItem:tabBar.item2];
            break;
        case 3:
            [tabBar setSelectedItem:tabBar.item3];
            break;
        case 4:
            //remove by raniy
//            [tabBar setSelectedItem:tabBar.item4];
            break;
        case 5:
            [tabBar setSelectedItem:tabBar.item5];
            break;
        default:
            break;
    }
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[self navigationController] setNavigationBarHidden:NO];
}

-(void) viewDidLoad
{
    [super viewDidLoad];
    [self fitIOS7];
    
    UIImage * backImage = [UIImage imageNamed:@"back-btn"];
    UIButton * leftBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBackBtn setTitle:@"" forState:UIControlStateNormal];
    [leftBackBtn setTitle:@"" forState:UIControlStateHighlighted];
    [leftBackBtn setImage:backImage forState:UIControlStateNormal];
    [leftBackBtn setFrame:CGRectMake(0, 0, 30, 18)];
    [leftBackBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBackBtn];
    self.view.clipsToBounds = YES;
    if(IOS7)
    {
        //支持iOS7，top导航条不计算
        self.edgesForExtendedLayout = UIRectEdgeNone;
//        self.extendedLayoutIncludesOpaqueBars = NO;
//        self.modalPresentationCapturesStatusBarAppearance = NO;
        
    }
    
    if (self.hideBackItem ||
        [self isKindOfClass:[JddLotteryHallViewController class]] ||
        [self isKindOfClass:[JddTogetherBuyViewController class]] ||
        [self isKindOfClass:[JddLotteryOpenViewController class]] ||
        [self isKindOfClass:[JddUserCenterViewController class]]) {
        leftBackBtn.hidden = YES;
    } else {
        leftBackBtn.hidden = NO;
    }
}

- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)fitIOS7
{
    if (IOS7) {
        //        self.view.bounds = CGRectMake(0, -20, self.view.frame.size.width, self.view.frame.size.height );
        
        //navigationBar titlecolor
        self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:UIColorRef(255, 255, 255),NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f]};
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
        self.navigationController.navigationBar.translucent = NO;
    }
}

@end
